--
-- Author: shunguo.chen
-- Date: 2016-08-09 14:53:14
--
-- RewardInvestPanel

local RewardInvestRender = import(".renders.RewardInvestRender")

local ClassRef = app.mvc.createPanelClass(...)

function ClassRef.create(node)
	local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.RewardInvestPanel))
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init()
	return sprite
end

function ClassRef:init(data)
	self.super.init(self, data)

	self._list = self._ui.bonus
	self._list:removeAllItems()
	self._list.createRender = function (list, idx)
		local items = list:getItems()
    	local render = items[idx]
    	if nil == render then
			render = RewardInvestRender.create()
			list:pushBackCustomItem(render)
		end
		return render
	end

	self._ui.Button_buy:addClickEventListener(function()
			executeFunc(self._onOperate, "buyInvest")
		end)
end

function ClassRef:onOperate(cb)
	self._onOperate = cb
end

function ClassRef:setInvested(b)
	self._ui.over:setVisible(b)
	self._ui.Button_buy:setVisible(not b)
	self._ui.rmb:setVisible(not b)
end

function ClassRef:setInvestGain(num)
	self._ui.num:setString(num)
end

function ClassRef:getList()
	return self._list
end

return ClassRef